package com.szxy.hotel.controller;

import com.szxy.hotel.entity.PageBean;
import com.szxy.hotel.entity.Vip;
import com.szxy.hotel.service.VipService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class VipController {
    @Resource(name = "vipService")
    VipService vipService;
    /**
     * 会员管理列表
     */
    @RequestMapping("/vipAndClientList.do")
    @ResponseBody
    public Map<String,Object> vipAndClientList(int currentPage){
        Map<String, Object> map = new HashMap<String, Object>();
        PageBean<Vip> pageBean = new PageBean<Vip>();
        //一页的记录数
        int pageSize = 8;
        //下标初始值
        int start = (currentPage - 1) * pageSize;
        //要查询的记录数
        int size = pageSize;
        //查询的所有Vip对象集合
        List<Vip> lists = vipService.findByPage(start, size);
        //Vip对象的总数
        List<Vip> list = vipService.selectCount();
        int count = list.size();
        if (count <= 0) {
            map.put("status", 1);
            map.put("message", "没有数据");
            map.put("result", null);
        } else {
            int totalCount = count;
            double tc = totalCount;
            int totalPage = (int) Math.ceil(tc / pageSize);
            pageBean.setCurrentage(currentPage);
            pageBean.setPageSize(pageSize);
            pageBean.setTotalCount(totalCount);
            pageBean.setTotalPage(totalPage);
            pageBean.setLists(lists);
            map.put("status", 0);
            map.put("message", "有数据");
            map.put("result", pageBean);
        }
        return map;
    }
}
